// 房间特性 - Hotel
import { get } from 'lodash';
import { DataTypes, UUIDV4 } from 'sequelize';
import { MySqlModel, getSequelize } from '../db';

class RoomFeature extends MySqlModel {

}

RoomFeature.init({
  id: {
    type: DataTypes.UUID, unique: 'id', allowNull: false, defaultValue: UUIDV4, validate: { isUUID: 4 }, primaryKey: true, comment: '主键'
  },
  hotel_id: {
    type: DataTypes.UUID, unique: 'hotel_id_code', allowNull: false, validate: { isUUID: 4 }, comment: '主体'
  },
  code: {
    type: DataTypes.STRING(50), unique: 'hotel_id_code', allowNull: false, comment: '代码'
  },
  name: {
    type: DataTypes.STRING(200), allowNull: false, comment: '名称'
  },
  disabled: {
    type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, comment: '禁用'
  },
  sequence: {
    type: DataTypes.INTEGER, allowNull: true, defaultValue: null, validate: { min: 0, max: 999999 }, comment: '排序'
  },
  created_at: {
    type: DataTypes.DATE, allowNull: false, comment: '创建时间'
  },
  updated_at: {
    type: DataTypes.DATE, allowNull: false, comment: '更新时间'
  },
  version: {
    type: DataTypes.INTEGER, allowNull: false, defaultValue: 0, comment: '版本控制'
  }
}, {
  sequelize: getSequelize(),
  tableName: 'room_features',
  comment: '房间特征'
});

// ConfigRoomFeature.beforeDestroy(async (instance, options) => {
//   const { transaction } = options;
//   const room = await getSequelize().models.Room
//     .findOne({
//       where: {
//         room_floor_id: instance.id
//       },
//       transaction
//     });
//   if (room) {
//     throw new Error(`Used By Member ${room.room}`);
//   }
// });

export default RoomFeature;
